home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_mysql.idb / usr / freeware / share / sql-bench / test-big-tables.z / test-big-tables
Encoding:
Text File  |  1999-10-18  |  3.1 KB  |  139 lines

  1. #!/bin/perl5
  2. #
  3. # Test of extreme tables.
  4. #
  5.  
  6. ##################### Standard benchmark inits ##############################
  7.  
  8. use DBI;
  9. use Benchmark;
  10.  
  11. $opt_loop_count=1000; # Change this to make test harder/easier
  12. $opt_field_count=1000;
  13.  
  14. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  15. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  16.  
  17. $opt_field_count=min($opt_field_count,$limits->{'max_columns'},
  18.              ($limits->{'query_size'}-30)/14);
  19.  
  20. $opt_loop_count*=10 if ($opt_field_count<100);    # mSQL has so few fields...
  21.  
  22. if ($opt_small_test)
  23. {
  24.   $opt_loop_count/=10;
  25.   $opt_field_count/=10;
  26. }
  27.  
  28.  
  29. print "Testing of some unusual tables\n";
  30. print "All tests are done $opt_loop_count times with $opt_field_count fields\n\n";
  31.  
  32.  
  33. ####
  34. ####  Testing many fields
  35. ####
  36.  
  37. $dbh = $server->connect();
  38. print "Testing table with $opt_field_count fields\n";
  39.  
  40. $sth = $dbh->do("drop table bench1");
  41.  
  42. my @fields=();
  43. my @index=();
  44. my $fields="i1";
  45. push(@fields,"$fields int");
  46. $values= "1," x ($opt_field_count-1) . "1";
  47. for ($i=2 ; $i <= $opt_field_count ; $i++)
  48. {
  49.   push(@fields,"i${i} int");
  50.   $fields.=",i${i}";
  51. }
  52.  
  53. $start_time=new Benchmark;
  54.  
  55. do_many($dbh,$server->create("bench1",\@fields,\@index));
  56. $sth = $dbh->do("insert into bench1 values ($values)") or die $DBI::errstr;
  57.  
  58. if ($opt_fast && $opt_server eq "pg")
  59. {
  60.   $server->vacuum($dbh);
  61. }
  62.  
  63. test_query("Testing select * from table with 1 record",
  64.        "Time to select_many_fields",
  65.        "select * from bench1",
  66.        $dbh,$opt_loop_count);
  67.  
  68. test_query("Testing select all_fields from table with 1 record",
  69.        "Time to select_many_fields",
  70.        "select $fields from bench1",
  71.        $dbh,$opt_loop_count);
  72.  
  73. test_query("Testing insert VALUES()",
  74.        "Time to insert_many_fields",
  75.        "insert into bench1 values($values)",
  76.        $dbh,$opt_loop_count);
  77.  
  78. if ($opt_fast && $opt_server eq "pg")
  79. {
  80.   $server->vacuum($dbh);
  81. }
  82.  
  83. test_command("Testing insert (all_fields) VALUES()",
  84.          "Time to insert_many_fields",
  85.          "insert into bench1 ($fields) values($values)",
  86.          $dbh,$opt_loop_count);
  87.  
  88. $sth = $dbh->do("drop table bench1") or die $DBI::errstr;
  89.  
  90. if ($opt_fast && $opt_server eq "pg")
  91. {
  92.   $server->vacuum($dbh);
  93. }
  94.  
  95. ################################ END ###################################
  96. ####
  97. #### End of the test...Finally print time used to execute the
  98. #### whole test.
  99.  
  100. $dbh->disconnect;
  101.  
  102. end_benchmark($start_time);
  103.  
  104.  
  105. ############################ HELP FUNCTIONS ##############################
  106.  
  107. sub test_query
  108. {
  109.   my($test_text,$result_text,$query,$dbh,$count)=@_;
  110.   my($i,$loop_time,$end_time);
  111.  
  112.   print $test_text . "\n";
  113.   $loop_time=new Benchmark;
  114.   for ($i=0 ; $i < $count ; $i++)
  115.   {
  116.     defined(fetch_all_rows($dbh,$query)) or die $DBI::errstr;
  117.   }
  118.   $end_time=new Benchmark;
  119.   print $result_text . "($count): " .
  120.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  121. }
  122.  
  123.  
  124. sub test_command
  125. {
  126.   my($test_text,$result_text,$query,$dbh,$count)=@_;
  127.   my($i,$loop_time,$end_time);
  128.  
  129.   print $test_text . "\n";
  130.   $loop_time=new Benchmark;
  131.   for ($i=0 ; $i < $count ; $i++)
  132.   {
  133.     $dbh->do($query) or die $DBI::errstr;
  134.   }
  135.   $end_time=new Benchmark;
  136.   print $result_text . "($count): " .
  137.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  138. }
  139.